// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/store'
import dayjs from 'dayjs';
// import ElementUI from 'element-ui';
// import VConsole from 'vconsole'
// var vConsole = new VConsole();
// import 'lib-flexible/flexible.js'
import './assets/js/adapter'
import Navigation from 'vue-navigation'
import './styles/main.css';
// import iView from 'iview';
import 'lib-flexible/flexible';
import IconSvg from 'vue2-svg-icon/Icon.vue';
import "./../src/styles/iconfont.css"
// import 'element-ui/lib/theme-chalk/index.css';
// import 'iview/dist/styles/iview.css';
import filters from '@/utils/filter'
// 签名
import vueEsign from 'vue-esign'
Vue.use(vueEsign)
// 低版本兼容
import Es6Promise from 'es6-promise'
require('es6-promise').polyfill()
Es6Promise.polyfill()

//loading
import  { LoadingPlugin } from 'vux'
Vue.use(LoadingPlugin)
import  { AlertPlugin } from 'vux'
Vue.use(AlertPlugin)
import  { ToastPlugin } from 'vux'
Vue.use(ToastPlugin,{time: 1500})
import { DatetimePlugin } from 'vux'
Vue.use(DatetimePlugin)
// 添加下面两行
import focusable from 'vue-tv-focusable';
Vue.use(focusable);
// Vue.use(iView)
// Vue.use(ElementUI);
Vue.component('iconSvg',IconSvg)

import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons'
import { far } from '@fortawesome/free-regular-svg-icons'
import { fab } from '@fortawesome/free-brands-svg-icons'
import { FontAwesomeIcon, FontAwesomeLayers, FontAwesomeLayersText } from '@fortawesome/vue-fontawesome'

library.add(fas, far, fab)

Vue.component('font-awesome-icon', FontAwesomeIcon)
Vue.component('font-awesome-layers', FontAwesomeLayers)
Vue.component('font-awesome-layers-text', FontAwesomeLayersText)

// let echarts = require('echarts/lib/echarts');
import echarts from 'echarts/lib/echarts'  //引入Echarts，

require('echarts/lib/chart/bar');
require("echarts/lib/chart/line");
require("echarts/lib/chart/pie");
require("echarts/lib/component/tooltip");
require("echarts/lib/component/toolbox");
require('echarts/lib/component/title');
require('echarts/lib/component/grid');
require('echarts/lib/component/legend');
require('echarts/lib/component/legendScroll');
require('echarts/lib/component/axisPointer');
require('echarts/lib/component/dataset');
require('echarts/lib/component/dataZoom');
require('echarts/lib/component/graphic');

Vue.prototype.$echarts = echarts  //定义为全局变量

Vue.use(Navigation, {router})
//添加Fastclick移除移动端点击延迟
const FastClick = require('fastclick')
FastClick.attach(document.body)
// 挂载公用方法
import Commom from './config/commom'
Vue.prototype.$commom = Commom.commom;
import http from './config/http'
Vue.prototype.$http = http;
import httpGet from './config/httpGet'
Vue.prototype.$httpGet = httpGet;
//绑定API
import API from './config/server';
Vue.prototype.$API = API;
//绑定请求
import axios from 'axios'
Vue.prototype.$axios = axios;
//绑定后台地址
import host from './config/host'

Vue.config.productionTip = false

Object.keys(filters).forEach(key => Vue.filter(key, filters[key]))
//显示当前时间
Vue.filter('getTime', function (value) {
  var date = new Date();
  var Y = date.getFullYear() + '-';
  var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
  var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
  var H = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
  var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
  return Y+M+D+H+m;
})

//如果不是全路径url,拼接图片url
Vue.filter('checkImgUrl', function (value) {
  if(value) {
    if(value.indexOf('http://') >= 0 || value.indexOf('https://') >= 0){
      return value;
    }else{
      return host.hostUrl + '/file/object?fileName=' + value;
    }
  } else {
    return
  }
})

// 时间戳转换为时间
Vue.filter('formatDate', (time, format = 'YYYY-MM-DD HH:mm:ss') => {
  let formatTime;
  if (time !== null) {
    const date = new Date(time);
    formatTime = dayjs(date).format(format);
  } else {
    formatTime = '-';
  }
  return formatTime;
});
// 时间戳转换为时间到几点
Vue.filter('formatDateHour', (time) => {
  let formatTime;
  if (time !== null) {
    const date = new Date(time);
    formatTime = dayjs(date).format('YYYY-MM-DD HH');
  } else {
    formatTime = '-';
  }
  return formatTime;
});
// 时间戳转换为时间
Vue.filter('formatDate1', (time) => {
  let formatTime;
  if (time !== null) {
    const date = new Date(time);
    formatTime = dayjs(date).format('YYYY-MM-DD');
  } else {
    formatTime = '-';
  }
  return formatTime;
});
// 时间戳转换为时间
Vue.filter('formatDate2', (time) => {
  let formatTime;
  if (time !== null) {
    const date = new Date(time);
    formatTime = dayjs(date).format('HH:mm:ss');
  } else {
    formatTime = '-';
  }
  return formatTime;
});
//分钟转换为多少天多少小时多少分钟
Vue.filter('timeStamp', (StatusMinute) => {
  if(StatusMinute>0){
    var day=parseInt(StatusMinute/60/24);
    var hour=parseInt(StatusMinute/60%24);
    var min= parseInt(StatusMinute % 60);
    StatusMinute="";
    if (day > 0){
        StatusMinute= day + "天";
    }
    if (hour>0){
        StatusMinute += hour + "小时";
    }
    if (min>0){
        StatusMinute += parseFloat(min) + "分";
    }
     return StatusMinute;

  }else if(StatusMinute<0){
    Math.abs(StatusMinute)
    let num = Math.abs(StatusMinute);
    var day=parseInt(num/60/24);
    var hour=parseInt(num/60%24);
    var min= parseInt(num % 60);
    num="";
    if (day > 0){
      num = "-"+ day + "天";
    }
    if(day>6){//当day大于7的时候，return;
      num = "-" + day + "天";
      return num;
    }
    if (hour>0 && num!=""){
      num += hour + "小时";
    } else{
      num += "-" + hour + "小时";
    }

    if(min>0 && num!=""){
      num += parseFloat(min) + "分";
    }else{
      num += parseFloat(min) + "-" + "分";
    }
     return num;
  }
});
Vue.filter('formatOnlyDate', (time) => {
  const date = new Date(time);
  return dayjs(date).format('YYYY-MM-DD');
});
Vue.filter('formatOnlyTime', (time) => {
  const date = new Date(time);
  return dayjs(date).format('HH:mm:ss');
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store: store,
  router,
  components: { App },
  template: '<App/>'
})
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
})


FastClick.prototype.focus = function (targetElement) {
  let length;
  if (targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') {
    length = targetElement.value.length;
    targetElement.focus();
    targetElement.setSelectionRange(length, length);
  } else {
    targetElement.focus();
  }
};

Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "H+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
